//package com.yy.aop;
//
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.Data;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.AfterReturning;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Array;
//import java.lang.reflect.Method;
//import java.text.SimpleDateFormat;
//import java.util.Arrays;
//import java.util.Date;
//
//
////------------------------------------------
//
//
//import com.yy.annotation.OperLog;
//import com.yy.Utils.ipUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.log4j.Logger;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.*;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//
//import javax.servlet.http.HttpServletRequest;
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//
///**
// * @Author: yy
// * @Date 2021/11/3 10:39
// */
//@Slf4j
//@Aspect
//@Component
//public class LogAspect {
//
//
//    private final Logger systemLog = Logger.getLogger("SystemLog");
//    private final Logger businessLog = Logger.getLogger("BusinessLog");
//
////    @Pointcut("execution(* com.six.backend.service.*.*(..))")
//
//    @Pointcut("@annotation(com.yy.annotation.OperLog)")
//    public void pointCut(){
//
//    }
//
//
//    @Before("pointCut()")
//    public void before(JoinPoint joinPoint){
//        handleLog(joinPoint, null);
//    }
//
//
//    @AfterReturning(pointcut = "pointCut()")
//    public void after(JoinPoint joinPoint)
//    {
//        handleLog(joinPoint, null);
//    }
//
//
//    @AfterThrowing(value = "pointCut()", throwing = "e")
//    public void doAfter(JoinPoint joinPoint, Exception e)
//    {
//        handleLog(joinPoint, e);
//    }
//
//    @Around("pointCut()")
//    public Object doAround(ProceedingJoinPoint joinPoint)
//    {
//        Object proceed=null;
//        handleLog(joinPoint, null);
//        try {
//            proceed = joinPoint.proceed();
//            return proceed;
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        }
//        return null;
//    }
//
//    private void handleLog(JoinPoint joinPoint, Exception e) {
//        try
//        {
//            OperLog logger = giveController(joinPoint);
//
//            if (logger == null)
//            {
//                return;
//            }
//            //获取request
//            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
//            HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
//
//            String signature = joinPoint.getSignature().toString();
//            //截取方法名
//            String methodName = signature.substring(signature.lastIndexOf(".")+1, signature.indexOf("("));
//            String longTemp = joinPoint.getStaticPart().toLongString();
//            //通过调用方法的目标对象通过反射获取它的类名
//            String classType = joinPoint.getTarget().getClass().getName();
//            Class<?> clazz = Class.forName(classType);
//
//            String clazzName = clazz.getName();
//
//            OperLog process = LogAspect.process(joinPoint);
//
//            Object[] args = joinPoint.getArgs();
//
//            ArrayList<String> params = new ArrayList<>();
//
//            for (Object arg : args) {
//                params.add(String.valueOf(arg));
//            }
//
//            String ipAddr = ipUtils.getIpAddr(request);
//
//            if(e != null) {
//                systemLog.error(String.format("所在位置相关信息:[%s]",longTemp));
//                systemLog.error(e);
//            }
//            businessLog.info(String.format("操作ip地址:[%s],模块:[%s],类型:[%s],描述:[%s],类名:[%s],方法名:[%s],入参:[%s]",
//                    ipAddr,
//                    process.operModule(),
//                    process.operType(),
//                    process.operDesc() ,
//                    clazzName,
//                    methodName,
//                    params));
//
//            log.info(String.format("操作ip地址:[%s],模块:[%s],类型:[%s],描述:[%s],类名:[%s],方法名:[%s],入参:[%s]",
//                    ipAddr,
//                    process.operModule(),
//                    process.operType(),
//                    process.operDesc() ,
//                    clazzName,
//                    methodName,
//                    params));
//        } catch (Exception exp)
//        {
//            systemLog.error("异常信息:[%s]",exp);
//            exp.printStackTrace();
//        }
//    }
//
//
//    /**
//     * 获得注解
//     * @param joinPoint
//     * @return
//     * @throws Exception
//     */
//    private static OperLog giveController(JoinPoint joinPoint) throws Exception {
//        Signature signature = joinPoint.getSignature();
//        MethodSignature methodSignature = (MethodSignature) signature;
//        Method method = methodSignature.getMethod();
//
//        if (method != null)
//        {
//            return method.getAnnotation(OperLog.class);
//        }
//        return null;
//    }
//
//    public static OperLog process(JoinPoint joinPoint) {
//
//        return ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(OperLog.class);
//    }
//
//
//    //--------------------------------------------------------
//
////
////    @Autowired
////    private ObjectMapper mapper;
////    /**
////     * 開始時間 訪問的類 訪問的方法
////     *
////     */
////    private Long visitTime;
////    private Class clazz;
////
////    @Pointcut("execution(public  * com.yy.controller.*.*(..))")
////    private void aspect(){}
////
////    @Before("aspect()")
////    public  void  before(JoinPoint joinPoint) throws NoSuchMethodException {
////        visitTime=System.currentTimeMillis();
////        Date date = new Date(visitTime);
////
////        clazz=joinPoint.getTarget().getClass();
////        String methodName = joinPoint.getSignature().getName();
////        Object[] args=joinPoint.getArgs();
////        Method method;
////        if (args==null||args.length==0) {
////            method =clazz.getMethod(methodName);
////        }else {
////            Class[] argsClasses = new Class[args.length];
////            for (int i = 0; i < args.length; i++) {
////                argsClasses[i]=args.getClass();
////            }
////            method=clazz.getMethod(methodName, argsClasses);
////        }
////
////        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
////        HttpServletRequest request = requestAttributes.getRequest();
////        log.info("============请求内容 开始===============");
////        String requestMethod = request.getMethod();
////        log.info("请求时间:"+  new SimpleDateFormat().format(date));
////        log.info("请求IP:"+request.getRemoteAddr());
////        log.info("请求地址:"+request.getRequestURI());
////        log.info("请求方式:"+request.getMethod());
////        log.info("请求类方法:"+joinPoint.getSignature());
////        log.info("请求类方法参数:"+ Arrays.toString(joinPoint.getArgs()));
////
////        if (clazz!=null&& method !=null) {
////            RequestMapping clazzAnnotation = (RequestMapping) clazz.getAnnotation(RequestMapping.class);
////            if (clazzAnnotation != null) {
////                String[] classValue = clazzAnnotation.value();
////                if ("GET".equals(requestMethod)){
////                    GetMapping methodAnnotation = method.getAnnotation(GetMapping.class);
////                    url(classValue, methodAnnotation!=null, methodAnnotation.value());
////                }else {
////                    PostMapping methodAnnotation = method.getAnnotation(PostMapping.class);
////                    url(classValue, methodAnnotation != null, methodAnnotation.value());
////                }
////
////            }
////            log.info("类名{}，方法名{}",clazz.getName(),methodName);
////        }
////        log.info("============请求内容 结束===============");
////    }
////
////        @AfterReturning(returning = "obj",pointcut = "aspect()")
////        public void  methodAfterReturning(Object obj){
////        long time = System.currentTimeMillis() - visitTime;
////        log.info("执行时长:{}ms",time);
////        log.info("============返回内容开始===============");
////        try {
////            log.info(mapper.writeValueAsString(obj));
////        } catch (JsonProcessingException e) {
////            e.printStackTrace();
////            log.error("发生错误",e);
////        }
////        log.info("============返回内容结束===============");
////
////    }
////    private void url(String[] classValue, boolean b, String[] value) {
////        String url;
////        if (b) {
////
////            url = classValue[0] + value[0];
////            log.info("url:{}", url);
////        }
////    }
//
//
//
//
//
//}
//
//
